import time

import allure
from selenium.webdriver.common.by import By

from bazhuayun.page.base_octopus_cloud import BaseOctopusCloud
from bazhuayun.utils.log_utils import logger


class OrdersListPage(BaseOctopusCloud):
    _CLICK_ORDERS_LIST = By.XPATH, '//*[text()="订单列表"]'
    _CLICK_ADDRESSEE = By.XPATH, '(//*[@class="el-input__inner"])[15]'
    _CLICK_PHONE = By.XPATH, '(//*[@class="el-input__inner"])[16]'
    _CLICK_FOUND = By.XPATH, '//*[text()="查询"]'
    _CLICK_REVISE_ORDERS = By.XPATH, '//*[text()="修改订单金额"]'
    _CLICK_ORDERS_AMOUNT = By.XPATH, '//*[@placeholder="请输入订单金额"]'
    _CLICK_DETERMINE = By.XPATH, '//*[@id="pane-0"]/div[36]/div/div[3]/div/div/button'
    _DETERMINE_TEXT = By.XPATH, '//*[@class="el-message__content"]'

    @allure.step("完成商品金额修改")
    def orders_list_page(self, name, phone, amount):
        # 点击订单列表
        self.find_ele(*self._CLICK_ORDERS_LIST).click()
        # 点击收件人
        time.sleep(2)
        self.find_ele(*self._CLICK_ADDRESSEE).click()
        self.find_ele(*self._CLICK_ADDRESSEE).send_keys(name)
        # 点击电话
        time.sleep(2)
        self.find_ele(*self._CLICK_PHONE).click()
        self.find_ele(*self._CLICK_PHONE).send_keys(phone)
        # 点击查找
        self.find_ele(*self._CLICK_FOUND).click()
        # 点击修改金额
        time.sleep(2)
        self.find_ele(*self._CLICK_REVISE_ORDERS).click()
        # 点击订单金额输入框
        time.sleep(2)
        self.find_ele(*self._CLICK_ORDERS_AMOUNT).click()
        self.find_ele(*self._CLICK_ORDERS_AMOUNT).clear()
        self.find_ele(*self._CLICK_ORDERS_AMOUNT).send_keys(amount)
        # 点击确定
        self.find_ele(*self._CLICK_DETERMINE).click()
        # 确认文本
        time.sleep(2)
        res = self.find_ele(*self._DETERMINE_TEXT)
        logger.info("完成商品金额修改")
        return res



